#include <thread>

#include "../../../common/log.h"
#include "../../../common/rabbitmq.h"
#include "gflags/gflags.h"

DEFINE_string(host, "127.0.0.1:5672", "rabbitmq服务器地址");
DEFINE_string(user, "root", "rabbitmq用户");
DEFINE_string(password, "123456", "对应用户的密码");

DEFINE_int32(level, 1, "日志等级");
DEFINE_bool(enable_debug, false, "调试模式");
DEFINE_string(path, "", "发布模式下, 日志输出到的文件路径");

void onMessage(const char* message, size_t size) {
    std::string msg;
    msg.assign(message, size);
    LOG_DEBUG("收到消息: {}", msg);
}

int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true);
    chat::initLogger(FLAGS_level, FLAGS_enable_debug, FLAGS_path);

    chat::MQClient consume(FLAGS_user, FLAGS_password, FLAGS_host);

    consume.declareCompoents("test-exchange", "test-queue",
                             AMQP::ExchangeType::direct, "test-routing-key");

    consume.consume("test-queue", "consume-tag", onMessage);

    std::this_thread::sleep_for(std::chrono::seconds(60));

    return 0;
}